﻿using System;
using System.Data;
using System.Collections.Generic;
using ORM.Annotations;
using Domain.Commons;
using System.Data.SqlClient;

namespace DBUtils
{
     public interface IDBWrapper : IDisposable
    {
        IDbConnection GetConnection();

        IDataReader Query(string sqlString, params IDataParameter[] parameters);

        int QueryForInt(string sqlString,params IDataParameter[] parameters);

        object QueryForObject(string sqlString, params IDataParameter[] parameters);

        IList<T> Query<T>(string sqlString, IDataRowMapper<T> rowMapper, params IDataParameter[] parameters) where T : class;

        T QueryScalar<T>(string sqlString) where T : class;

        T QueryScalar<T>(string sqlString, params IDataParameter[] parameters) where T : class;

        int ExecuteNonQuery(string sqlString, params IDataParameter[] parameters);

        IList<T> List<T>() where T : class,new();

        IList<T> List<T>(string condition, params IDataParameter[] parameters) where T : class,new();

        T Get<T>(object id) where T : class,new();

        int Insert(object entity);

        int Update(object entity);

        int Delete(object entity);

        int Delete<T>(object id) where T : class;

        /// <summary>
        /// If Insert method return 0 then execute Update method.
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        int Save(object entity);

        #region Db Transaction

        void BeginTransaction();

        void Commit();

        void RollBack();

        #endregion
    }
}
